package com.exam.scjp5.objectives.section_3;

import java.text.NumberFormat;
import java.util.Locale;

public class ExampleNumberFormat
{
    public static void main(String args[])
    {
        Locale locale = new Locale("en","us");
        float value = 116.1469f;
        float value2 = 2.00f;
        
        NumberFormat nf[] = new NumberFormat[4];
        nf[0] = NumberFormat.getInstance(locale);
        nf[1] = NumberFormat.getCurrencyInstance(Locale.FRANCE);
        nf[2] = NumberFormat.getIntegerInstance(Locale.FRANCE);
        nf[3] = NumberFormat.getPercentInstance(locale);
        
        System.out.println("nf[0] = " + nf[0].format(value));
        nf[0].setMaximumFractionDigits(2);
        nf[0].setMaximumIntegerDigits(2);
        nf[0].setMinimumFractionDigits(2);
        nf[0].setMinimumIntegerDigits(2);
        System.out.println("nf[0] = " + nf[0].format(value));
        System.out.println("nf[0] = " + nf[0].format(value2));
        
        nf[1].setMaximumFractionDigits(2);
        nf[1].setMaximumIntegerDigits(2);
        nf[1].setMinimumFractionDigits(2);
        nf[1].setMinimumIntegerDigits(4);
        System.out.println("");
        System.out.println("nf[1] = " + nf[1].format(value));
        System.out.println("nf[1] = " + nf[1].format(value2));
        
        System.out.println("");
        System.out.println("nf[2] = " + nf[2].format(value));
        System.out.println("nf[2] = " + nf[2].format(value2));
        
        System.out.println("");
        System.out.println("nf[3] = " + nf[3].format(value));
        System.out.println("nf[3] = " + nf[3].format(value2));
        
    }
}
